package com.coscon.controller.api;

import com.coscon.controller.base.BaseController;
import com.coscon.model.IrcaCmd;
import com.coscon.model.api.ApiResponse;
import com.coscon.model.api.ResponseCode;
import com.coscon.service.IrcaCmdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.awt.*;
import java.io.IOException;
import java.util.List;

/**
 * 针对APP控制的API
 */
@RestController
@RequestMapping("/jm/api/")
@Slf4j
public class ApiByAppController extends BaseController {

    @Resource(name = "ircaCmdService")
    private IrcaCmdService cmdService;

    /**
     * 预留测试接口
     * @return
     */
    @GetMapping(value = "/test")
    public ApiResponse<Boolean> testApi() {
        ApiResponse<Boolean> r = ApiResponse.createBySuccess();
        return r;
    }

    /**
     * 执行IrcaCmd 命令
     * @param ircaCmd
     * @return
     * @throws IOException
     */
    @PostMapping(value = "/execIrcaCmdCmd")
    public ApiResponse<Boolean> execIrcaCmdCmd(@RequestBody(required = true) IrcaCmd ircaCmd) throws IOException {
        log.debug(ircaCmd.toString());
        ApiResponse<Boolean> r = ApiResponse.createByError(ResponseCode.OK);
        boolean flag = false;
        try {
            flag =  cmdService.execCmd(ircaCmd,null);
        } catch (AWTException e) {
            e.printStackTrace();
        }
        r.setData(flag);//返回执行结果
        return r;
    }






}
